<?
include("include/role.php");
include("include/mysql.config.php");
session_start();
$action=$_GET["ac"];

if("update"==$action){
    $name=$_SESSION["admin_name"];
    $pass=$_SESSION["admin_pass"];
    $pass1=$_POST["pass1"];
    $pass2=$_POST["pass2"];
    $old=$_POST["oldpass"];
    $error=array();
    if($old==null){
        $error[]="旧密码不能为空";
    }
    if($pass1==null){
        $error[]="新密码不能为空";
    }
    if($pass2==null){
        $error[]="新密码需重复输入";
    }
    if($pass2!=$pass1){
        $error[]="两次密码需一至";
    }
    
    
    if($pass!=md5($old)){
    
        $error[]="当前密码错误";
    
    }
     

    if(count($error)==0){
        $pass1=md5($pass1);
        $sql="update admin set admin_password='$pass1' where admin_name='$name'";
        $result=mysql_query($sql,$conn);
        if($result==true){
            $_SESSION["message"]="密码更改成功!";
            header("Location:admin.php");
            exit;
        }
        else{
            $error="发生错误，修改失败";
        }
    }
}
if("quit"==$action){

    unset($_SESSION["admin_name"]);           
    unset($_SESSION["admin_pass"]);           
    header("Location:login.php");


}
?>
<!DOCTYPE html>
<html>
<head>
    <title>账号管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link href="asset/admin.css" rel="stylesheet" type="text/css">
    <script src="asset/jquery-1.6.4.min.js" ></script>
    <script src="asset/jquery.validate.min.js" ></script>
    <script>
$(function(){
    $("#form1").validate({
		rules: {
			oldpass: "required",
			pass1: {
				required: true,
				minlength: 5
			},
			pass2: {
				required: true,
				minlength: 5,
				equalTo: "#pass1"
			}
		},
		messages: {
			oldpass: "请输入当前密码",
			pass1: {
				required: "请输入新密码",
				minlength: "密码最小为5位"
			},
			pass2: {
				required: "请再次输入新密码",
				minlength: "密码最小为5位",
				equalTo: "两次密码需要一致"
			}
		}
	});
});
	
       
    </script>
</head>
<body>
<? include("include/menu.php"); ?>
    <div class="error">
    <?
    for($i=0;$i<count($error);$i++){
        echo "<li>";
        echo $error[$i];
        echo "</li>";
    }

    ?>
    </div>
<form id="form1" action="user.php?ac=update" method="post">
<table class="user">
<caption class="table-caption">账号修改</caption>
<colgroup>
    <col width="80px">
    </col>
    <col>
    </col>
<colgroup>
<tr><td>旧密码</td><td><input  type="password" name="oldpass" id="oldpass" /> </td> </tr>
<tr><td>新密码</td><td><input  type="password" name="pass1" id="pass1" /> </td> </tr>
<tr><td>重　复</td><td><input  type="password" name="pass2" id="pass2" /> </td> </tr>
<tr><td><input type="submit" value="保存" /></td> </tr>
<tr><td colspan=2><p><span class="notice">注意:密码中不能使用=,or,'和"等敏感字符</span></p></td></tr>
</form>
</body>
</html>
